<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Constructs a new Message Formatter</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.messageformatter.html">MessageFormatter</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="messageformatter.formatmessage.html">MessageFormatter::formatMessage</a></div>
 <div class="up"><a href="class.messageformatter.html">MessageFormatter</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="messageformatter.create" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MessageFormatter::create</h1>
  <h1 class="refname">MessageFormatter::__construct</h1>
  <h1 class="refname">msgfmt_create</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">MessageFormatter::create</span> -- <span class="refname">MessageFormatter::__construct</span> -- <span class="refname">msgfmt_create</span> &mdash; <span class="dc-title">Constructs a new Message Formatter</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-messageformatter.create-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格 (method)
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="modifier">static</span>
   <span class="type"><a href="class.messageformatter.html" class="type MessageFormatter">MessageFormatter</a></span> 
   <span class="methodname"><strong>MessageFormatter::create</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>
   )</div>

  <p class="para rdfs-comment">
   面向对象风格 (constructor):
  </p>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="methodname"><strong>MessageFormatter::__construct()</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>
   )</div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="class.messageformatter.html" class="type MessageFormatter">MessageFormatter</a></span> 
   <span class="methodname"><strong>msgfmt_create</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>
   )</div>

  <p class="para rdfs-comment">
   Constructs a new Message Formatter
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-messageformatter.create-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">locale</code></em></dt>

     <dd>

      <p class="para">
       The locale to use when formatting arguments
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">pattern</code></em></dt>

     <dd>

      <p class="para">
       The pattern string to stick arguments into. 
       The pattern uses an &#039;apostrophe-friendly&#039; syntax; it is run through
       <a href="http://www.icu-project.org/apiref/icu4c/umsg_8h.html#9da796210146ff51d395affe4928f0b7" class="link external">&raquo;&nbsp;umsg_autoQuoteApostrophe</a> 
       before being interpreted.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-messageformatter.create-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The formatter <span class="type"><a href="language.types.object.html" class="type object">object</a></span>
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-messageformatter.create-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2506">
   <p><strong>Example #1 <span class="function"><strong>msgfmt_create()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">msgfmt_create</span><span style="color: #007700">(</span><span style="color: #DD0000">"en_US"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,number,integer}&nbsp;monkeys&nbsp;on&nbsp;{1,number,integer}&nbsp;trees&nbsp;make&nbsp;{2,number}&nbsp;monkeys&nbsp;per&nbsp;tree"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">msgfmt_format</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">4560</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">123</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4560</span><span style="color: #007700">/</span><span style="color: #0000BB">123</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$fmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">msgfmt_create</span><span style="color: #007700">(</span><span style="color: #DD0000">"de"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,number,integer}&nbsp;Affen&nbsp;auf&nbsp;{1,number,integer}&nbsp;Bäumen&nbsp;sind&nbsp;{2,number}&nbsp;Affen&nbsp;pro&nbsp;Baum"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">msgfmt_format</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">4560</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">123</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4560</span><span style="color: #007700">/</span><span style="color: #0000BB">123</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-2507">
   <p><strong>Example #2 OO example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fmt&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MessageFormatter</span><span style="color: #007700">(</span><span style="color: #DD0000">"en_US"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,number,integer}&nbsp;monkeys&nbsp;on&nbsp;{1,number,integer}&nbsp;trees&nbsp;make&nbsp;{2,number}&nbsp;monkeys&nbsp;per&nbsp;tree"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(array(</span><span style="color: #0000BB">4560</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">123</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4560</span><span style="color: #007700">/</span><span style="color: #0000BB">123</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$fmt&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MessageFormatter</span><span style="color: #007700">(</span><span style="color: #DD0000">"de"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,number,integer}&nbsp;Affen&nbsp;auf&nbsp;{1,number,integer}&nbsp;Bäumen&nbsp;sind&nbsp;{2,number}&nbsp;Affen&nbsp;pro&nbsp;Baum"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(array(</span><span style="color: #0000BB">4560</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">123</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4560</span><span style="color: #007700">/</span><span style="color: #0000BB">123</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
   <div class="cdata"><pre>
4,560 monkeys on 123 trees make 37.073 monkeys per tree
4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum
</pre></div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-messageformatter.create-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="messageformatter.format.html" class="function" rel="rdfs-seeAlso">msgfmt_format()</a> - Format the message</span></li>
    <li class="member"><span class="function"><a href="messageformatter.parse.html" class="function" rel="rdfs-seeAlso">msgfmt_parse()</a> - Parse input string according to pattern</span></li>
    <li class="member"><span class="function"><a href="messageformatter.geterrorcode.html" class="function" rel="rdfs-seeAlso">msgfmt_get_error_code()</a> - Get the error code from last operation</span></li>
    <li class="member"><span class="function"><a href="messageformatter.geterrormessage.html" class="function" rel="rdfs-seeAlso">msgfmt_get_error_message()</a> - Get the error text from the last operation</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.messageformatter.html">MessageFormatter</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="messageformatter.formatmessage.html">MessageFormatter::formatMessage</a></div>
 <div class="up"><a href="class.messageformatter.html">MessageFormatter</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
